package org.md.budzik.problems;

import java.math.BigInteger;

/**
 * Obsługa liczb Bella.
 * @author Wiezzel
 *
 */
public class BellNumber extends OneArgOp {

	public BellNumber(Expression ex) {
		super(ex);
	}

	protected BigInteger computeOperation(BigInteger value) throws ParseException {
		if (value.compareTo(BigInteger.ZERO) < 0)
			throw new ParseException("Liczby Bella są zdefiniowane dla x >= 0");
		if (value.equals(BigInteger.ZERO))
			return BigInteger.ONE;
		else {
			BigInteger ans = BigInteger.ZERO;
			for (BigInteger i = BigInteger.ZERO; i.compareTo(value) < 0; i = i.add(BigInteger.ONE))
				ans = ans.add(Binomial.binom(value.subtract(BigInteger.ONE), i).multiply(computeOperation(i)));
			return ans;
		}
	}

	protected String operationSymbol() {
		return "bell";
	}

}
